﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Serilog;
using Serilog.Events;
using System;
using System.Configuration;
using System.Diagnostics;
using System.IO;

namespace doris__dotnet_console_test
{
    class Program
    {
        static void Main(string[] args)
        {
            ConfigLog();
            Serilog.Log.Information("Program Starting");

            DorisSqlHelper.ConnectionString = ConfigurationManager.ConnectionStrings["DorisConnStr"].ConnectionString;
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            long lastTime = 0;
            DorisTest.QueryTest();
            //for (int i = 0; i < 10; i++)
            //{
            //    DorisTest.QueryTest();
            //    Serilog.Log.Information($"Query {i}耗时{stopwatch.ElapsedMilliseconds - lastTime}ms");
            //    lastTime = stopwatch.ElapsedMilliseconds;
            //}

            //for (int i = 0; i < 10; i++)
            //{
            //    DorisTest.InQuery_UNI_Test();
            //    Serilog.Log.Information($"IN_Query {i}耗时{stopwatch.ElapsedMilliseconds - lastTime}ms");
            //    lastTime = stopwatch.ElapsedMilliseconds;
            //}
            stopwatch.Stop();
            Serilog.Log.Information("Program Ended");
            Console.ReadKey();
        }

        private static void ConfigLog()
        {
            var maxFileSize = 1024 * 1024 * 20L;
            static string LogFilePath(string LogEvent) => $@"log{Path.DirectorySeparatorChar}.txt";
            string outputTemplate = "{NewLine}时间:{Timestamp:yyyy-MM-dd HH:mm:ss.fff} 级别:{Level} {Message}{NewLine}" + new string('-', 50) + "{NewLine}";
            Log.Logger = new LoggerConfiguration()
                .Enrich.FromLogContext()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                .WriteTo.Console(outputTemplate: outputTemplate)
                .WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level >= LogEventLevel.Verbose).WriteTo.File(
                    LogFilePath(""),
                    rollingInterval: RollingInterval.Day,
                    outputTemplate: outputTemplate,
                    fileSizeLimitBytes: maxFileSize,
                    rollOnFileSizeLimit: true,
                    retainedFileCountLimit: 10000,
                    retainedFileTimeLimit: TimeSpan.FromDays(120)
                   )
                )
               .CreateLogger();
        }
    }
}
